package com.jr.controller;

import com.jr.entry.User;

import com.jr.pojo.PageHelper;
import com.jr.service.impl.UserServiceImpl;
import com.jr.util.ResultObject;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SuppressWarnings("all")
@RestController /*替换@RestController=@Controller + @ResponseBody*/
@RequestMapping("/Us/")
public class UserController {

    @Autowired
    private UserServiceImpl userMapperService;
    @Autowired
    private ResultObject result;

    @RequestMapping("add")
    public ResultObject add(User user) {
        int register = userMapperService.register(user);
        result.setStatus(register);
        result.setResult("成功");
        return result;
    }

    @RequestMapping("login")
    public ResultObject login(User user) {
        User register = userMapperService.login(user);
        if (register != null) {
            result.setStatus(1);
            result.setResult(register);
        } else {
            result.setStatus(-1);
        }
        System.out.println(register);
        return result;
    }

    @RequestMapping("quanxian")
    public ResultObject selectBlogByUserId(int uid, PageHelper pageHelper) {
        RowBounds rowBounds = new RowBounds((pageHelper.getPage() - 1) * 5, 5);
        result.setResult(userMapperService.selectBlogByUserId(uid, rowBounds));
        return result;
    }
}
